/*
 * @filename CloudConfiguration.java
 * @author barry
 * @version 0.0.1
 * @date 2019年12月26日
 */
package com.bnzj.cloud.config;

import com.bnzj.cloud.security.DefaultCurrentUserService;
import com.bnzj.core.rest.CurrentUserService;
import com.bnzj.core.util.SymmetricEncrypt;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;

/**
 * @author barry
 * @date 2019-12-26
 */
@Configuration
@EnableConfigurationProperties(value = {CloudProperties.class})
@ComponentScan(basePackages = {"com.bnzj.core", "com.bnzj.cloud"})
@EnableJpaRepositories(basePackages = {"com.bnzj.cloud.business.**.persistence.repository"})
@EntityScan(basePackages = {"com.bnzj.cloud.business.**.persistence.entity"})
//@ServletComponentScan(basePackages = {"com.bnzj.cloud.business.**.web.jakarta"})
public class CloudConfiguration {

    @Bean
    @ConditionalOnMissingBean(value = {CurrentUserService.class})
    public DefaultCurrentUserService currentUserService(){
        return new DefaultCurrentUserService();
    }

    static {
        String secretKey = SymmetricEncrypt.generateKey();
        SymmetricEncrypt.init(secretKey);
    }
}
